home *** CD-ROM | disk | FTP | other *** search
- /* Float2Str255.c by Stefan Sinclair Oct. 1995
- Apple provided a routine for converting integers (type 'long') to
- into Str255 format (NumToString), but they forgot floating point conversion!
- This simple routine converts from floating point (type 'double')
- into Str255 format.
- */
-
- #include <stdio.h> /* You need this one */
- /* #include <Macheaders> <- You will need to un-comment this line.
- Also, p2cstr and c2pstr are now defined in Apple's Macintosh headers.
- */
-
- void Float2Str255(double fPt, Str255 pStr)
- {
- int myErr;
-
- p2cstr(pStr); /* Convert to (char *) */
- myErr = sprintf((char *)pStr, "%G", fPt); /* print floating point number */
- /* You can easily change the output format by replacing '%G' with whatever makes you happy. */
- if(myErr >= 0) /* Did everything go as planned? */
- c2pstr((char *)pStr); /* Back to Str255 */
- /* else, here you will want to handle any error that might occur for some freak reason. */
- }